package com.qf.advice;/*
 *徐韬
 *2021/10/18
 *16:03
 */

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class MyAnno {
    @Pointcut("execution(* com.qf.service.impl.GradeServiceimpl.add(..))")
    public void pc(){}
    @Pointcut("execution(* com.qf.service.impl.GradeServiceimpl.modfiy(..))")
    public void pc2(){}
    @Pointcut("execution(* com.qf.service.impl.GradeServiceimpl.show(..))")
    public void pc3(){}
    @Pointcut("execution(* com.qf.service.impl.GradeServiceimpl.remove(..))")
    public void pc4(){}
    @Pointcut("execution(* com.qf.service.impl.GradeServiceimpl.showAll(..))")
    public void pc5(){}
    @Before("pc()")
    public void before(){
        System.out.println("增强日志");
    }
    @AfterReturning(value = "pc2()",returning = "result")
    public void afterReturn(Object result){
        System.out.println("后置增强执行 接收结果为："+result);
    }
    @Around("pc3()")
    public void around(ProceedingJoinPoint proceedingJoinPoint)throws Throwable{
        try {
            System.out.println("环绕增强，事务开启");
            Object res = proceedingJoinPoint.proceed();
            System.out.println("事务提交");
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            System.out.println("事务回滚");
        }
    }
    @AfterThrowing(value = "pc4()",throwing = "e")
    public void afterThrowing(Exception e){
        System.out.println("异常增强"+e.getMessage());
    }
    @After("pc5()")
    public void after(){
        System.out.println("最终增强执行了");
    }

}
